<?php
namespace Admin\Controller;

use Think\Controller;

class BannerController extends BackController
{
	/**
	 * 配置文件列表页
	 */
    public function index()
    {
		$this->page('banner','','',10);
		$this->display();
    }

	/**
	 * 配置文件添加，修改页
	 */
	public function info() {
		/* 初始化 */
		$urlSuccess = U('Banner/index');
		$model = 'banner';
		$primarykey = 'id';
		$getParam = 'id';
		/* 初始化 */

		if(IS_POST) {
			
			$this->uploadOne('src'); // 上传图片
			$d = D($model);
			if(!$d->create()) {
				$this->error($d->getError());
			} else {
				$id = I('post.'.$primarykey,'','intval');
				if(empty($id)) {
					$msg = $d->add();
				} else {
					$msg = $d->save();
				}
				if(empty($msg)) {
					$this->error('操作失败！');
				} else {
					$this->success('操作成功！',$urlSuccess);
				}
			}
			die();
		}

		$id = I('get.'.$getParam,'','intval');
		$info = M($model)->find($id);
		$this->assign('info',$info);

		if(C('CLASS_IMG')) {
		$where['pid'] = 0;
		$pidClass = D('class')->where($where)->select();
		$class = keyList($pidClass,'id');
		$this->assign('class',$class); // 分类
		}

		$this->display();
	}
	
	/**
	 * 删除
	 */
	public function del() {
		$getParam = 'id';
		$model = 'banner';
		$urlSuccess = U('Banner/index');
		$id = I('get.'.$getParam,'','intval');
		$msg = D($model)->del($id);
		if(empty($msg)) {
			$this->error('删除失败！');
		} else {
			$this->success('删除成功！',$urlSuccess);
		}
	}

	/**
	 * 测试
	 */
	public function form() {
		echo $this->createForm('banner');
	}

	public function table() {
		echo $this->createTableall('banner');
	}

}
